package com.zretc.controller;

import com.zretc.entity.Type;
import com.zretc.service.TypeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: bLUeSuMMerDreamer
 * @createTime: 2020-07-23 14:51
 */
@Controller
@RequestMapping("/type")
public class TypeController {
    private static final Logger logger = LoggerFactory.getLogger(TypeController.class);
    @Autowired
    private TypeService typeService;

    @RequestMapping("/getAllType")
    public @ResponseBody
    List<Type> getAllType() {
        logger.debug("========================postMan=========================");
        List<Type> types = typeService.getAllType();
        logger.info(types.toString());
        return types;
    }

    @RequestMapping("/getTypeByParam")
    public @ResponseBody
    Type getTypeByParam(String typeId, String typeName) {
        logger.debug("=====================================");
        Map<String, Object> params = new HashMap<>();
        if (typeId != null) {
            params.put("typeId", typeId);
        }
        if (typeName != null) {
            params.put("typeName", "%" + typeName + "%");
        }

        Type types = typeService.getTypesByParam(params).get(0);

        return types;
    }
}
